package cn.fangline.controller;

import cn.fangline.mapper.UserMapper;
import cn.fangline.model.User;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 抽离
 * @since 2017-07-18
 */
@Controller
public class UserController {

    @Autowired
    private UserMapper userMapper;


    /**
     *
     * @return
     *
     *
     * {
    "offset": 0,
    "limit": 2147483647,
    "total": 4,
    "size": 1,
    "pages": 4,
    "current": 1,
    "searchCount": true,
    "openSort": true,
    "orderByField": null,
    "records": [
    {
    "id": 11,
    "userName": "2",
    "age": 1,
    "birthDate": null,
    "country": null,
    "province": null,
    "city": null
    }
    ],
    "condition": null,
    "asc": true,
    "offsetCurrent": 0
    }
     */
    @ResponseBody
    @RequestMapping("user")
    public Page<User> getUser(){
        Page<User> page = new Page<User>(1, 1);
        EntityWrapper<User> ew = new EntityWrapper<User>();
        /*
         * 查询条件，SQL 片段(根据常用的写SQL的方式按顺序添加相关条件即可)
		 */
        ew.eq("user_name", 2);
        List<User> paginList = userMapper.selectPage(page, ew);
        page.setRecords(paginList);
        return page;
    }

    @ResponseBody
    @RequestMapping("/index")
	public String index(){
        return "hello";
    }
}
